define(function (require, exports, module) {	
    var tpl1 = require("/mobile/tpl/redpacket/winecouExchange.tpl");
    var AjaxReturn = require('/plugins/extend/AjaxReturn');   
    AjaxReturn.ajaxPacket("/app/member/redpacket/availableWineCouponsJSON.html", "get", tpl1, "#winecouExchange");             
   $("#winecouExchange").delegate(".winecouExchangeli","click",function(e){
	   if($(this).children("input.wcExchangeimg").length==0){    
			$(this).append("<input type='checkbox' />");
			$(this).append("<label class='wcExchangelab'></label>");
			$(".winecouExchangeli input:nth-of-type(2)").attr("class","wcExchangeimg");	
			var Ids= $(this).children().val();					
			$(this).children(".wcExchangeimg").attr("value",Ids);	
		}else{
			$(this).children("input.wcExchangeimg").remove(); 
			$(this).children("label").remove();
		}
   });   
   $("#winecouExchange").delegate(".btn_winecoupon","click",function(e){
	var getCheckedV = $(".wcExchangeimg");
   	var len = getCheckedV.length;
   	/*alert(len);
   	return false;*/
   	var voucherIds = [];
		if(len==0||len%6!=0){
			layer.alert("请选择6或6的倍数张的酒卡！");
			return false;
		}else{
			for(var i=0;i<len;i++){
				voucherIds.push(getCheckedV[i].value);				
			}
			$.ajax({
				url:"/app/member/redpacket/wineExchange.html",
				traditional:true,
				data:{"wineCouponsIds":voucherIds},
				success:function(data){
					layer.alert(data.resMsg);
					if(data.result){
						$(".winecouExchangeli").trigger("click");
					}
				}
			});
		}
   });    		 	
});